package ui.tp3.TP3Wicket;

import org.apache.wicket.Component;
import org.apache.wicket.Page;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.image.Image;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.PropertyListView;
import org.apache.wicket.request.resource.ContextRelativeResource;

import ui.tp3.modelo.Esfera;
import ui.tp3.modelo.Personaje;

public class EsferasPersonajeModalWindow extends WebPage{

	private ModalWindow modalSheng;
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	
	
	public EsferasPersonajeModalWindow(final Personaje pers,ModalWindow modalwindow){  
		add(new PropertyListView<Esfera>("esferasObtenidas", pers.getEsferasObtenidas()) {

			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;

			@Override
			protected void populateItem(ListItem<Esfera> e) {
				Esfera esfera = (Esfera) e.getModelObject();
				e.add(new Image("imgEsf", new ContextRelativeResource("/"
						+ esfera.getNombre() + ".jpg")));
				
			}
		});
		
	add(modalSheng = new ModalWindow("modalSheng"));
	modalSheng.setTitle("El personaje " + pers.getNombre() + " ha llamado a ShengLong!!!!");
	modalSheng.setCookieName("modal-Sheng");
	modalSheng.setPageCreator(new ModalWindow.PageCreator(){

		public Page createPage() {

			return new ShenLongModalWindow(pers,modalSheng);
		}
		
	});
	
	AjaxLink modalShenLong = new AjaxLink("showModalShen"){

		@Override
		public void onClick(AjaxRequestTarget target) {
			modalSheng.show(target);
		}
		
	};
	
	
	
	modalShenLong.setVisible(false);
	
	if(pers.getCantEsferasObtenidas() ==7){
		modalShenLong.setVisible(true);
	}
	
	add(modalShenLong);
	
	}
	
}
